<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="include/peizhi.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
        
        <title>后台管理中心</title> 
		<link rel="stylesheet" href="${ctx}/css/pintuer.css" /> 
		<link rel="stylesheet" href="${ctx}/css/admin.css" /> 
        <script type="text/javascript" src="${ctx}/js/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="${ctx}/js/alertNew.js"></script>
    </head>
  	<body style="background-color:#f2f9fd;"> 
	  <jsp:include page="include/header.jsp" flush="true"/>
  <div class="admin"> 
  	<div class="panel admin-panel">
	  <div class="panel-head"><strong class="icon-reorder"> 内容列表</strong></div>
	  <div class="padding border-bottom">  
	  <button type="button" class="button border-yellow" onclick="window.location.href='/region/region'"><span class="icon-plus-square-o"></span> 添加内容</button>
	  </div>
	  <table id='pagehtml' class="table table-hover text-center">
	    
	  </table>
	</div>
	<form id="pageForm" action="${ctx}/region/getList">
		<input type="hidden" name="pageNo" id="pageNo" value="0" /> 
		<input type="hidden" name="pageSize" id="pageSize" value="10" /> 
		<input id='lastPage' type="hidden">
	</form>
   <!-- <iframe scrolling="auto" rameborder="0" src="info.jsp" name="right" width="100%" height="100%"></iframe>  -->
  </div> 
 </body>
 <script type="text/javascript">
 	$(document).ready(function(){
		page(1,$("#pageSize").val());
		function page(ct,size,t){
			var last = $('#lastPage').val();
			if(t=='prev'){
				ct = Number($('#pageNo').val())-1;
			}
			if(t=='next'){
				ct = Number($('#pageNo').val())+1;
			}
			if(t=='search'){
				ct = Number($('#lastPage').val());
			}
			if(ct!=1){
				if(ct<0||ct>last){return ;}//如果不在包含的页数则不变
			}
			$('#pageNo').val(ct);
			$('#pageSize').val(size);
			$.ajax({
				url:$('#pageForm').attr('action'),
				type:"post",
				data:$('#pageForm').serialize(),
				success:function(data){
					var list = data.list;
					var html='';
					for (var i = 0; i < list.length; i++) {
						html = html + pageAppend(list[i]);
					}
					html = listhead + html;
					html = html + data.html;
					$("#pagehtml").html(html);
					$('#lastPage').val(data.countpage);
					
					/* $("#searchInput").click(function(){
						alert("尾页");
					}); */
				}
			});  
		}
		var listhead='<tr>'+
		      '<th width="12%">中文州</th>'+
		      '<th width="12%">英文州</th>'+
		      '<th width="12%">中文国家</th>'+
		      '<th width="12%">英文国家</th>'+
		      '<th width="12%">中文地区</th>'+
		      '<th width="12%">英文地区</th>'+
		      '<th width="12%">地区编码</th>'+
		      '<th width="12%">操作</th>'+
		    	'</tr>';
		var listhtml = "<tr id={8}del>";
			  listhtml = listhtml + "<td>{0}</td>";
		      listhtml = listhtml + "<td>{1}</td>";     
		      listhtml = listhtml + "<td>{2}</td>";
		      listhtml = listhtml + "<td>{3}</td>";
		      listhtml = listhtml + "<td>{4}</td>";
		      listhtml = listhtml + "<td>{5}</td>";
		      listhtml = listhtml + "<td>{6}</td>";
		      listhtml = listhtml + "<td><a class='button border-red' href='javascript:void(0)' onclick='del({7})'><span class='icon-trash-o'></span> 删除</a></td>";
			  listhtml = listhtml + "</tr>";
		function pageAppend(data){
			return listhtml.replace('{0}',data.cState)
			.replace('{1}',data.eState)
			.replace('{2}',data.cCountry)
			.replace('{3}',data.eCountry)
			.replace('{4}',data.cCity)
			.replace('{5}',data.eCity)
			.replace('{6}',data.regionCode)
			.replace('{7}',data.id)
			.replace('{8}',data.id);
		}
		function pageGo(size){
			var last = $("#last").val();
			if(last!=''){
				page(last,size);
			}else{
				alert("选页框不可为空");
			}
			
		}
 	});
	//删除
	function del(id){
		alert("是否删除","deleteAdv("+id+")");
	};
	function deleteAdv(id){
		doOk();
		if(id!='' && id != null){
				$.ajax({
					url:"${ctx}/region/delete",
					type:"post",
					data:"id="+id,
					success:function(data){
						if(data=='0'){
							alert("删除成功");
							$("#"+id+"del").hide();
							/* var a = $("#pageNo").val();
							var b = $("#pageSize").val();
							page(parseInt(a)-1,b); */
						}else{
							alert("删除异常，请刷新页面重新删除");
						}
					}
				});
		}else{
			alert("删除异常，请刷新页面重新删除");
		}
		
	}
</script>
</html>